﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq.SqlClient;
namespace TraCuuTinRaoVat
{
    public partial class QuanLyChuyenMucChinh : System.Web.UI.Page
    {
        static List<String> dsUseName = new List<string>();
        static List<String> dsEmail = new List<string>();
        static List<String> dsCMND = new List<string>();
      static  int temp1 = 1;
      static int temp2 = 1;
      static int temp3 = 1;
      //static string s1 = "Trùng Tên đăng nhập";
        protected void Page_Load(object sender, EventArgs e)
        {

           if (!IsPostBack)
            {
                lblTrungTenDN.Visible = false;
                lblTrungCMND.Visible = false;
                lblTrungEmail.Visible = false;
                LinQ_RaoVatDataContext danhsach = new LinQ_RaoVatDataContext();
                var query = from Tin_Rao_Vat in danhsach.NGUOI_DUNGs
                            select Tin_Rao_Vat.TenDangNhap;

                var query1 = from Tin_Rao_Vat in danhsach.NGUOI_DUNGs
                             select Tin_Rao_Vat.Email;

                var query2 = from Tin_Rao_Vat in danhsach.NGUOI_DUNGs
                             select Tin_Rao_Vat.SoCMND;

                // DropDownList1.DataSource = query;
                //DropDownList1.DataBind();
                foreach (String nd in query)
                {
                    dsUseName.Add(nd.Trim());
                }


                foreach (String nd in query1)
                {
                    dsEmail.Add(nd);
                }

                foreach (String nd in query2)
                {
                    dsCMND.Add(nd.Trim());
                }

                if (temp1 == 0)
                {
                    lblTrungTenDN.Visible = true;
                    lblTrungTenDN.Text = "Trùng tên đăng nhập ";
                }

                if (temp2 == 0)
                {
                    lblTrungEmail.Visible = true;
                    lblTrungEmail.Text ="Trùng Email";
                }

                if (temp3 == 0)
                {
                    lblTrungCMND.Visible = true;
                    lblTrungCMND.Text = " Trùng CMND";
                }
            }
          
            
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.Value.Length == 20)
                args.IsValid = false;
            else
            {
                if (args.Value.Length < 6)
                    args.IsValid = false;
                else
                    args.IsValid = true;
            }
        }

    

      
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

            lblTrungTenDN.Visible = false;
            lblTrungCMND.Visible = false;
            lblTrungEmail.Visible = false;
              temp1 = 1;
             temp2 = 1;
              temp3 = 1;
            string s = e.NewValues[1].ToString().Trim();
            string s1 = e.NewValues[3].ToString().Trim();
            string s2 = e.NewValues[5].ToString().Trim();
            
            //string s = "abc";
            for (int i = 0; i < dsUseName.Count; i++)
            {
                if ((s == dsUseName[i]) && (s != e.OldValues[1].ToString().Trim()))
                {
                    temp1 = 0;
                    Response.Redirect("UpdateAndDeleteTaiKhoan.aspx");
               }


            }


            for (int i = 0; i < dsEmail.Count; i++)
            {
                if ((s1 == dsEmail[i])&&(s1!= e.OldValues[3].ToString().Trim()))
                {
                    temp2 = 0;
                    Response.Redirect("UpdateAndDeleteTaiKhoan.aspx");
                  
                }
               
            }

            for (int i = 0; i < dsCMND.Count; i++)
            {
                if ((s2 == dsCMND[i])&&(s2!= e.OldValues[5].ToString().Trim()))
                {
                    temp3 = 0;
                    Response.Redirect("UpdateAndDeleteTaiKhoan.aspx");
                
                }           

            }
          
        }

    }
}